package edu.wpi.cs509.representation;

import java.io.Serializable;

/**
 * This class contains the minimal set of information about a game 
 * in order to display a joinable or observable game on the UI.
 * 
 * @author afoltan
 *
 */
public class GameListItem implements Serializable {

	// Serializable version
	private static final long serialVersionUID = 1L;
	
	// Game fields 
	private long gameID;
	private String player1 = null;
	private String player2 = null;
	
	// No default constructor
	@SuppressWarnings("unused")
	private GameListItem() {}
	
	/**
	 * Constructor for a joinable game
	 * 
	 * @param gameID - the unique gameID
	 * @param p1 - player 1 name - must not be null
	 */
	public GameListItem( long gameID, String p1 ) {
		this.gameID = gameID;

		if (p1 == null) {
			throw new IllegalArgumentException();
		}

		this.player1 = p1;
	}
	
	/**
	 * Constructor for an observable game
	 * 
	 * @param gameID - the unique game ID
	 * @param p1 - player 1 name - must not be null
	 * @param p2 - player 2 name - must not be null
	 */
	public GameListItem( long gameID, String p1, String p2 ) {
		this.gameID = gameID;
		
		if (p1 == null || p2 == null) {
			throw new IllegalArgumentException();
		}
		
		this.player1 = p1;
		this.player2 = p2;
	}
	
	/**
	 * Retrieves the game ID
	 * @return
	 */
	public long getGameID() {
		return gameID;
	}
	
	/**
	 * Retrieves the player1 string name
	 * @return
	 */
	public String getPlayer1Name() {
		if (player1 != null) {
			return player1;
		} else {
			return "Player1";
		}
	}
	
	/**
	 * Retrieves the player2 string name
	 * @return
	 */
	public String getPlayer2Name() {
		if (player2 != null) {
			return player2;
		} else {
			return "Player2";
		}
	}
	
	/**
	 * Indicates whether this game is joinable or not.
	 * Joinable games have only player 1
	 * @return
	 */
	public boolean isJoinable() {
		return (player2 == null);
	}

	/**
	 * Indicates whether this game is observable or not.
	 * Observable games have two players.
	 * @return
	 */
	public boolean isObservable() {
		return ((player1 != null) && (player2 != null));
	}

}
